package com.boarsoft.boar;

import java.io.IOException;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.boarsoft.common.Util;

public class BaseConfig {
	private final static Logger log = LoggerFactory.getLogger(BaseConfig.class);
	private final static Properties prop = new Properties();

	static {
		try {
			log.info("Load boar-base config.properties ...");
			prop.load(BaseConfig.class.getClassLoader().getResourceAsStream("config.properties"));
		} catch (IOException e) {
			log.error("Error on load config.properties.", e);
		}
	}

	// 全局私有存储空间根目录
	public static final String PATH_PRIVATE = prop.getProperty("PATH.PRIVATE");
	// 全局公享存储空间根目录（可被 HTTP访问）
	public static final String PATH_PUBLIC = prop.getProperty("PATH.PUBLIC");
	public static final int AGENTX_PORT = getInt("agentx.port", 9925);
	/** 目录树根节点ID，以兼容各数据库对char类型补空格问题，默认32位字符串 */
	public static final String DIR_ROOT = prop.getProperty("dir.root", "00000000000000000000000000000000");
	/** 环境变量 */
	public static final String SYS_ENV = prop.getProperty("SYS.ENV", "DEV");

	public static String getString(String key, String value) {
		return prop.getProperty(key, value);
	}

	public static int getInt(String key, int value) {
		return Util.str2int(prop.getProperty(key), value);
	}
}